﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace WebApplication4
{
    public abstract class HttpAsyncHandlerBase : IHttpAsyncHandler
    {
        public abstract Task ProcessRequestAsync(HttpContext context);

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            var task = ProcessRequestAsync(context);
            return Nito.AsyncEx.AsyncFactory.ToBegin(task, cb, extraData);
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            Nito.AsyncEx.AsyncFactory.ToEnd(result);
        }

        public void ProcessRequest(HttpContext context)
        {
            EndProcessRequest(BeginProcessRequest(context, null, null));
        }

        public virtual bool IsReusable
        {
            get { return true; }
        }
    }
}